package com.pangu.strategy.calculate.context;

import com.pangu.strategy.calculate.component.AbstractComponent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Linbizhao
 * @description:
 * @since 2023/11/20 13:57
 */
@Slf4j
@Component
public class StrategyContext {

    private static final Map<String, AbstractComponent> strategyMap = new HashMap<>();

    @Autowired
    public StrategyContext(Map<String, AbstractComponent> strategyMap) {
        StrategyContext.strategyMap.clear();
        strategyMap.forEach(StrategyContext.strategyMap::put);
        log.info(">>> strategyMap:{}", strategyMap);
    }

    public AbstractComponent loadStrategy(String strategyComponent) {
        return strategyMap.get(strategyComponent);
    }
}
